﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Crawler
{
    class XmlSettings
    {
        List<string> allowUriList = new List<string>();
        
        public XmlSettings()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("XmlSettings.xml");

            XmlNode node = doc.SelectSingleNode("XmlSettings/Node");
            _name = node.Attributes["name"].Value;
            _startUri = node.Attributes["uri"].Value;

            XmlNodeList nodeList = doc.SelectNodes("XmlSettings/Node/Allow");
            foreach (XmlNode node2 in nodeList)
            {
                string uri = node2.Attributes["uri"].Value;
                if (!String.IsNullOrEmpty(uri))
                {
                    int index = allowUriList.BinarySearch(uri);
                    if (index < 0)
                    {
                        allowUriList.Insert(~index, uri);
                    }

                }
            }
        }

        private string _name = "";
        public string Name 
        {
            get
            {
                return _name;
            }
        }

        private string _startUri = "";
        public string StartUri
        {
            get
            {
                return _startUri;
            }
        }

        public bool IsAllowedUri(string uri)
        {
            if (String.IsNullOrEmpty(uri)) return false;
            if (allowUriList.BinarySearch(uri) >= 0) return true;
            return false;
        }
    }
}
